#ifndef GATE_LISTENER_EVENT_HANDLER_H
#define GATE_LISTENER_EVENT_HANDLER_H
#include "gate_event_handler.h"

namespace utility
{
namespace network
{
    class gate_listener_event_handler : public gate_event_handler
    {
        typedef std::map<fake_socket, gate_client_session *> session_container;
    public:
        typedef gate_listener_event_handler * pointer;

        gate_listener_event_handler(gate_listener_impl * gatelistener);
        // standard destructor
        virtual ~gate_listener_event_handler();

        // handler when receive msg
        virtual void on_receive(const char * message, uint32 message_length);

        // handler when connection disconnected
        virtual void on_disconnected();

        // handler when any error occurred
        virtual void on_error(int32 error_code, const char * error_message);

        void set_session(const utility::network::session *);

        virtual void broadcast(std::set<gate_client_session *> & sessions, void * message, size_t message_length);

    private:
        virtual session * _get_session();

        virtual session_mgr * _get_session_mgr();

        virtual void _on_subsession_disconnected(gate_client_session *);

        void _req_connect(gate_protocol_header * header);
    private:
        utility::network::session * session_;
        gate_listener_impl * gate_listener_;

    };
}
}
#endif // endif of GATE_LISTENER_EVENT_HANDLER_H
